package com.czkevin.guicontrolsapi.controls;

import org.bukkit.event.inventory.InventoryClickEvent;
import com.czkevin.guicontrolsapi.Window;

public abstract class GUIControl {

    public abstract void onClick(InventoryClickEvent event, int localX, int localY);

    private Window window = null;
    private int x, y;

    public final void internal_DeployToWindow(Window window, int x, int y) {
        if(this.window != null) throw new IllegalStateException("Already deployed to a window! ");
        this.window = window;
        this.x = x;
        this.y = y;
    }
    public final void internal_RemoveFromWindow() {
        this.window = null;
        this.x = -1;
        this.y = -1;
    }

    public final Window getWindow() {
        return window;
    }

    public int getX() {
        return x;
    }

    public int getY() {
        return y;
    }

    public abstract int getWidth();
    public abstract int getHeight();

    public final boolean isOrigin(int x, int y) {
        return this.x == x && this.y == y;
    }

    public final void setLocation(int newX, int newY) {
        Window ref = window;
        ref.setControl(x, y, null);
        ref.setControl(newX, newY, this);
    }

    public abstract void onRender(boolean force);

}
